#ifndef SYSCALL_H_
#define SYSCALL_H_

/*
Copyright (C) 2011 Salil Bhagurkar

This file is part of illusion

illusion is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

illusion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with illusion.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <kernel/types.h>

//If you change the syscall numbers, don't forget to rebuild the entire kernel
//and apps. Most importantly, modify the static syscall numbers used in
//apps/load.s
//Also, update the syscall names in syscall.c for syscall tracing

#define SYS_VERSION 0						//Get the version of the system
#define SYS_RELEASE 1						//Yield the current process to give CPU time to other processes
#define SYS_GETPID 2						//Get the current process ID
#define SYS_OPEN 3							//This will open the vfs_node and make a file_id for the process
#define SYS_CLOSE 4							//This will close the vfs_node that was open in the process
#define SYS_READ 5							//Read an open file
#define SYS_WRITE 6							//Write to an open file
#define SYS_RENAME 7						//Rename a file
#define SYS_GETINFO 8						//Get information about a file (struct sys_info below)
#define SYS_CREATE 9						//Create a new file
#define SYS_CHANGESTATE 10					//Change the open state of an open file
#define SYS_READSTREAM 11					//Read from an alternate stream of a file other than the default data stream
#define SYS_WRITESTREAM 12					//Write to an alternate stream of a file other than the default data stream
#define SYS_GETAPIMOD 13					//Get the APIMOD interface request function address
#define SYS_PRINT 14						//Prints out to the console
#define SYS_READINPUT 15					//Reads from the standard input
#define SYS_GETCHILD 16						//Gets the first child of an open file
#define SYS_NEXTCHILD 17					//Gets the next sibling
#define SYS_ARGS 18							//Get the length and arguments of the arguments passed to an app
#define SYS_CREATEPROCESS 19				//Create a new process
#define SYS_EXITPROCESS 20					//To be called by a process to exit _itself_
#define SYS_GETPARENT 21					//Get the parent of a file
#define SYS_GETINFO1 22						//Get additional information about a file (struct sys_info1 below)
#define SYS_GETCURRENT 23					//Get the current working file
#define SYS_DELETE 24						//Delete a file
#define SYS_SETCURRENT 25					//Set the current working file
#define SYS_GETDEV 26						//Device traversal in user space: Gets the first device
#define SYS_NEXTDEV 27						//Gets the next device	//TODO Merge these two system calls
#define SYS_RESUMEPROCESS 28				//Resume a process from sleep
#define SYS_PAUSEPROCESS 29					//Pause a process to enter sleep state
#define SYS_GETPAGES 30						//Get memory pages: The way to allocate memory
#define SYS_FREEPAGES 31					//Give back memory pages when you don't need them
#define SYS_REDIRECTOUT 32					//Redirect output to a file //TODO Need redirect input system call
#define SYS_WAITFORPROCESS 35				//Wait for a process to exit
#define SYS_KILLPROCESS 36					//Kill a process
#define SYS_DETECTFS 37						//Detect a file system: Checks if a file has a file system inside it
#define SYS_MOUNTFS 38						//Mount a file system to create a new device that contains the file structure
#define SYS_TRY 43							//Enter system call try mode: By default, system calls end the process if it causes an error in the syscall
#define SYS_EXITTRY 44						//Exit system call try mode: Return to default

//Debugging system calls: Implementation changed to debug the user process / kernel execution of that user process
#define SYS_FOO 40
#define SYS_FOO_ENTER 41
#define SYS_FOO_LEAVE 42


int syscall(uint_t no, u32 param0, u32 param1, u32 param2,
		u32 param3, u32 param4);

//Called by the exception handler
void sys_exitprocess();

#define SYS_INFO_NAMELEN 256
#define SYS_INFO_PATHLEN 256

struct sys_info1 {
	char path[SYS_INFO_PATHLEN];
};

struct sys_info {
	char name[SYS_INFO_NAMELEN];
	uint_t length;
	uint_t child_count;
};

extern bool in_syscall;

#endif /* SYSCALL_H_ */
